<?php

namespace App\Jobs;

use App\Services\Warehouse\ConsignmentNoteService;
use App\Services\Warehouse\OrderGoodsInventoryCarryingDetailService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class CancelConsignmentNoteQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $jobdata;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(array $orderinfo)
    {
        $this->jobdata=$orderinfo;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(ConsignmentNoteService $consignmentNoteService,OrderGoodsInventoryCarryingDetailService $orderGoodsInventoryCarryingDetailService)
    {
        $order_info=$this->jobdata;
        $returndata=$consignmentNoteService->CancelConsignmentNote([$order_info['FBillNo']]);
        $data=[
            'order_sn'=>$order_info['FCarriageNO'],
        ];
        if(!empty($returndata['Number'])){
            $data['o_status']=8;
        }else{
            $data['o_status']=9;
        }
        return $orderGoodsInventoryCarryingDetailService->UpdateO_statusBatch($data);
    }
}
